<template>
	<view>
		
		<view class="listen-container">
			<view class="lc-title">
				填写选课报名表单
			</view>
			<view class="stu-form">
				<u-form :model="form" ref="uForm">
			
					<u-select v-model="courseShow" :list="courseList" @confirm="confirm"></u-select>
					<u-form-item prop="name" label-width="200rpx" label="学员姓名" required="true">
						<u-input v-model="form.name" placeholder="请输入姓名" />
					</u-form-item>
					<u-form-item prop="phone" label-width="200rpx" label="联系电话" required="true">
						<u-input v-model="form.phone" placeholder="请输入联系电话" />
					</u-form-item>
				</u-form>
				<u-button @click="submit" type="primary">提交</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		drawCouponSchoolOutside
	} from '@/utils/api.js'
	export default {
		data() {
			return {
				form: {
				
					eventsCouponId: '',
					name: '',
					phone: '',
					type: null
				},

				rules: {
				
					name: [{

						required: true,
						message: '请填写学员姓名',
						trigger: ['change', 'blur'],
					}],
					phone: [{
						required: true,
						message: '请填写联系电话',
						trigger: ['change', 'blur'],
						validator: (rule, value, callback) => {
							return this.$u.test.mobile(value) || this.$u.test.landline(value);
						},
					}],
				},
				courseShow: false,
				courseList: [],
				subjectId: '',
			}
		},
		onLoad(options) {
			console.log("options",JSON.parse(options.item) );
			this.form.eventsCouponId = JSON.parse(options.item).id
			this.form.type = JSON.parse(options.item).type
		
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			// courseShowBtn() {
			// 	console.log("22");
			// 	this.courseShow = true
			// },
			// confirm(e) {
			// 	console.log("2", e);
			// 	this.form.courseName = e[0].label
			// 	this.form.courseId = e[0].value
			// },
			submit() {
				this.$refs.uForm.validate(async (valid) => {
					if (valid) {
						console.log('验证通过', this.form);
						const {
							data,
							code
						} = await drawCouponSchoolOutside(this.form)
						if (code === 200) {
							uni.showToast({
								title: `抢购成功`,
								icon: 'none',
								duration: 2000
							});
						
						
							uni.navigateBack({
								delta:1,
							})
					

						}

					} else {
						console.log('验证失败');
					}
				});
			},
		
		}
	}
</script>

<style>
	.listen-top {
		display: flex;
		padding: 20rpx;
		justify-content: space-around;
		height: 200rpx;

	}

	.lt-left {
		margin-top: 25rpx;
	}

	.lt-right {
		width: 260rpx;
	}

	.tl-title {
		font-size: 48rpx;
		font-weight: bold;
	}

	.tl-intro {
		font-weight: bold;
		margin-top: 10rpx;
	}

	.listen-container {
		height: calc(100vh - 290rpx);
		background-color: #fff;
		padding: 20rpx;
	}

	.lc-title {
		font-weight: bold;
	}

	.stu-form {
		padding: 20rpx;
	}
</style>